// todo: 定义应用程序的主题，包括字体大小和样式
// app_theme.dart
import 'package:flutter/material.dart';
import '../constants/app_sizes.dart';
import 'app_colors.dart';
import 'app_text_theme.dart';
// import 'package:flex_color_scheme/flex_color_scheme.dart';

/* */
class AppTheme {
  static ThemeData get lightTheme => ThemeData(
        useMaterial3: true,
        colorScheme: AppColors.lightColorScheme(),
        textTheme: AppTextTheme.buildTextTheme(AppColors.lightColorScheme()),
        appBarTheme: const AppBarTheme(
          backgroundColor: AppColors.primaryColor,
          foregroundColor: Colors.white,
          // backgroundColor: AppColors.lightColorScheme().surface,
          // foregroundColor: AppColors.lightColorScheme().onSurface,
          surfaceTintColor: Colors.transparent,
          elevation: 2.0,
          centerTitle: true,
          iconTheme: IconThemeData(
            color: Colors.white,
            size: Sizes.p20,
            // color: Colors.white,
          ),
        ),
        cardTheme: CardTheme(
          elevation: 2,
          surfaceTintColor: AppColors.lightColorScheme().surface,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(12),
          ),
        ),
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            foregroundColor: AppColors.lightColorScheme().onPrimary,
            backgroundColor: AppColors.lightColorScheme().primary,
            padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
            elevation: 2,
            textStyle: AppTextTheme.buildTextTheme(AppColors.lightColorScheme())
                .labelLarge,
          ),
        ),
        inputDecorationTheme: InputDecorationTheme(
          filled: true,
          fillColor: AppColors.neutral20,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(8),
            borderSide: BorderSide.none,
          ),
          contentPadding: const EdgeInsets.symmetric(
            horizontal: 16,
            vertical: 14,
          ),
        ),
        floatingActionButtonTheme: FloatingActionButtonThemeData(
          backgroundColor: AppColors.lightColorScheme().primary,
          foregroundColor: AppColors.lightColorScheme().onPrimary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
        ),
        listTileTheme: const ListTileThemeData(
          subtitleTextStyle: TextStyle(
            fontSize: 12,
            color: AppColors.neutral70,
          ),
          contentPadding:
              EdgeInsets.symmetric(horizontal: Sizes.p20, vertical: 0),
          horizontalTitleGap: 16,
          iconColor: Colors.black,
        ),
        dividerTheme: const DividerThemeData(
          color: AppColors.neutral30,
          thickness: 1,
          space: 1,
        ),
      );

  static ThemeData get darkTheme => ThemeData(
        useMaterial3: true,
        colorScheme: AppColors.darkColorScheme(),
        textTheme: AppTextTheme.buildTextTheme(AppColors.darkColorScheme()),
        appBarTheme: AppBarTheme(
          backgroundColor: AppColors.darkColorScheme().surface,
          foregroundColor: AppColors.darkColorScheme().onSurface,
          surfaceTintColor: Colors.transparent,
          elevation: 1,
          centerTitle: true,
          iconTheme: const IconThemeData(
            // color: AppColors.darkColorScheme().onSurface,
            color: Colors.white,
          ),
        ),
        cardTheme: CardTheme(
          elevation: 2,
          surfaceTintColor: AppColors.darkColorScheme().surface,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(12),
          ),
        ),
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            foregroundColor: AppColors.darkColorScheme().onPrimary,
            backgroundColor: AppColors.darkColorScheme().primary,
            padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
            elevation: 2,
            textStyle: AppTextTheme.buildTextTheme(AppColors.darkColorScheme())
                .labelLarge,
          ),
        ),
        inputDecorationTheme: InputDecorationTheme(
          filled: true,
          fillColor: AppColors.neutral90,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(8),
            borderSide: BorderSide.none,
          ),
          contentPadding: const EdgeInsets.symmetric(
            horizontal: 16,
            vertical: 14,
          ),
        ),
        floatingActionButtonTheme: FloatingActionButtonThemeData(
          backgroundColor: AppColors.darkColorScheme().primary,
          foregroundColor: AppColors.darkColorScheme().onPrimary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
        ),
        listTileTheme: const ListTileThemeData(
          contentPadding:
              EdgeInsets.symmetric(horizontal: Sizes.p20, vertical: 0),
          horizontalTitleGap: 16,
          iconColor: Colors.black,
        ),
        dividerTheme: const DividerThemeData(
          color: AppColors.neutral70,
          thickness: 1,
          space: 1,
        ),
      );

  // 动态主题切换
  static ThemeData getTheme(BuildContext context) {
    final brightness = MediaQuery.platformBrightnessOf(context);
    return brightness == Brightness.dark ? darkTheme : lightTheme;
  }
}
